package com.enjoy.rocketmq.quickstart;

import com.enjoy.rocketmq.Util;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class Producer {
    public static void main(String[] args) throws Exception {

        Util.loadProperties();


        DefaultMQProducer producer = new DefaultMQProducer("group_a");

        producer.setNamesrvAddr(System.getProperty("nameserver.addr"));
        producer.start();
        for (int i = 0; i < 2; i++) {
            Message message = new Message("topic_a", "hello,rocketmq".getBytes(RemotingHelper.DEFAULT_CHARSET));
            System.out.println("i = " + i);
            // 这个方法是单向发送消息
            // 没有返回值，也没有回调，就是只管把消息发出去就行了
            producer.sendOneway(message);
        }

        producer.shutdown();

        System.out.println("发送完成");
    }
}
